/*
 * @Descripttion: 
 * @version: 
 * @Author: Ansel
 * @Date: 2020-02-26 22:55:19
 * @LastEditors: Ansel
 * @LastEditTime: 2020-03-16 20:59:33
 */
var arr = [1,4,3,6,7,8,2];

// let newArr = arr.map(function(item,index,arr){
//     return item + 1;
// });
// console.log(newArr);

// let newArr1 = arr.reduce(function(after,currentValue,index,arr){
//     return after + currentValue;
// });

// console.log(newArr1,arr);


Array.prototype._map = function(fn ,thisValue){
    let newArr = [];

    let currentThis = thisValue || null;
    this.reduce((lastValue,indexValue,index,arr) => {
        // console.log(fn.call(currentThis,lastValue,index,arr))
        newArr.push(fn.call(currentThis,indexValue,index,arr));
        // console.log(lastValue,indexValue)
        // return indexValue;
    },currentThis)
    return newArr;
}

function fn(item,index,arr){
    return item * 3;
}
let newArr3 = arr._map(fn);
console.log(newArr3);